﻿using ProjectFootball.MVC.Foundation.Repositories;
using ProjectFootball.MVC.Models.EntityFramework.Contexts;
using ProjectFootball.MVC.Models.EntityFramework.Entities;
using System;

namespace ProjectFootball.MVC.Models.RepositoryProviders
{
    public sealed class RepositoryProvider : IRepositoryProvider, IDisposable
    {
        private PFDBContext context = new PFDBContext();

        private IDataRepository<Campaign> campaignRepository;
        public IDataRepository<Campaign> CampaignRepository
        {
            get { return campaignRepository = campaignRepository ?? new DataRepository<Campaign>(context); }
        }

        private IDataRepository<Competition> competitionRepository;
        public IDataRepository<Competition> CompetitionRepository
        {
            get { return competitionRepository = competitionRepository ?? new DataRepository<Competition>(context); }
        }

        private IDataRepository<Country> countryRepository;
        public IDataRepository<Country> CountryRepository
        {
            get { return countryRepository = countryRepository ?? new DataRepository<Country>(context); }
        }

        private IDataRepository<LookupCompetition> lookupCompetitionRepository;
        public IDataRepository<LookupCompetition> LookupCompetitionRepository
        {
            get { return lookupCompetitionRepository = lookupCompetitionRepository ?? new DataRepository<LookupCompetition>(context); }
        }

        private IDataRepository<LookupMatch> lookupMatchRepository;
        public IDataRepository<LookupMatch> LookupMatchRepository
        {
            get { return lookupMatchRepository = lookupMatchRepository ?? new DataRepository<LookupMatch>(context); }
        }

        private IDataRepository<LookupPerson> lookupPersonRepository;
        public IDataRepository<LookupPerson> LookupPersonRepository
        {
            get { return lookupPersonRepository = lookupPersonRepository ?? new DataRepository<LookupPerson>(context); }
        }

        private IDataRepository<LookupTeam> lookupTeamRepository;
        public IDataRepository<LookupTeam> LookupTeamRepository
        {
            get { return lookupTeamRepository = lookupTeamRepository ?? new DataRepository<LookupTeam>(context); }
        }

        private IDataRepository<Match> matchRepository;
        public IDataRepository<Match> MatchRepository
        {
            get { return matchRepository = matchRepository ?? new DataRepository<Match>(context); }
        }

        private IDataRepository<MatchEvent> matchEventRepository;
        public IDataRepository<MatchEvent> MatchEventRepository
        {
            get { return matchEventRepository = matchEventRepository ?? new DataRepository<MatchEvent>(context); }
        }

        private IDataRepository<Person> personRepository;
        public IDataRepository<Person> PersonRepository
        {
            get { return personRepository = personRepository ?? new DataRepository<Person>(context); }
        }

        private IDataRepository<Team> teamRepository;
        public IDataRepository<Team> TeamRepository
        {
            get { return teamRepository = teamRepository ?? new DataRepository<Team>(context); }
        }

        private IDataRepository<TeamVersion> teamVersionRepository;
        public IDataRepository<TeamVersion> TeamVersionRepository
        {
            get { return teamVersionRepository = teamVersionRepository ?? new DataRepository<TeamVersion>(context); }
        }

        private IDataRepository<Venue> venueRepository;
        public IDataRepository<Venue> VenueRepository
        {
            get { return venueRepository = venueRepository ?? new DataRepository<Venue>(context); }
        }

        public void SaveChanges()
        {
            context.SaveChanges();
        }

        public void Dispose()
        {
            context.Dispose();
        }
    }
}